package com.icloud.system.boot.service.impl;

import com.icloud.common.core.api.ResultCode;
import com.icloud.common.web.enums.FileTypeEnum;
import com.icloud.common.web.exception.ApiException;
import com.icloud.common.web.util.AuthUtil;
import com.icloud.common.web.util.S3Util;
import com.icloud.common.web.vo.FileUrlVO;
import com.icloud.system.boot.service.AppFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import software.amazon.awssdk.services.s3.S3Client;

@Slf4j
@Service
public class AppFileServiceImpl implements AppFileService {
    @Autowired
    private S3Client s3Client;
    @Autowired
    private AuthUtil authUtil;

    @Override
    public FileUrlVO uploadArticle(MultipartFile file) {
        long size = file.getSize();
        if(size>1024*1024*200){
            throw new ApiException(ResultCode.FILE_UPLOAD_IMG_TOO_LARGE);
        }
        Long customerId = authUtil.getUserId();
        return S3Util.uploadAppFile(s3Client, file, FileTypeEnum.ARTICLE.getCode(), customerId);
    }
}
